fix(session): make eager status backfill opt-in - #1040
Conversation
|
The approach is sound — making the eager Env parsing doesn't match project convention. Minor, non-blocking:
Since #982 is closed, it's worth opening a companion issue for this trigger so the failure mode is tracked somewhere searchable. Verified locally: 236/236 |
rmyndharis
left a comment
There was a problem hiding this comment.
Converting my earlier comment into a formal review, since the env-parsing point is a merge blocker for me:
- Simplify the flag read to
process.env.STATUS_SEED_ON_READY === 'true'. - Register
STATUS_SEED_ON_READYin thecheckBoollist insrc/config/env.validation.ts, consistent with the other boolean flags.
Everything else in the earlier comment stands as non-blocking. Happy to approve once those two land.
|
Hi @rmyndharis ! Just a friendly follow-up on this PR. I've addressed the previous feedback and pushed the requested changes in the latest commits. When you have a chance, could you please take another look? If everything looks good now, I'd really appreciate it if you could merge this PR. Please let me know if there's anything else you'd like me to update. Thanks for your time and for maintaining OpenWA! 🙏 |
Summary
This PR makes the eager WhatsApp Status history backfill on session
readyopt-in instead of unconditional.On an affected freshly paired
whatsapp-web.jsaccount, OpenWA reachedREADYsuccessfully but WhatsApp revoked the companion at the first scheduled WhatsApp Web reload, approximately five minutes later. After isolating OpenWA-specific work performed duringready, the trigger was narrowed to the immediatestatus@broadcasthistory read used to seed the Status store.Disabling only that read allowed the same account, browser, container, Web build, and production configuration to survive the reload and remain connected. Live Status events continue to work; only the one-time backfill of statuses that predate the connection is disabled by default.
Related to #982. This is a follow-up to the onboarding-modal handling in #998: auto-dismissing the modal improved onboarding visibility but did not stop the deterministic logout for this account.
Problem
Observed behavior
For the affected account, every fresh pairing followed the same sequence:
whatsapp-web.jsemitsauthenticatedandready.READYand the page is usable.CONNECTEDwithhasSynced=trueand a validWWebJSruntime.?post_logout=1&logout_reason=0.whatsapp-web.jsemitsdisconnected: LOGOUT, removes the LocalAuth profile, and OpenWA can only return to a fresh QR.The result is a deterministic loss of credentials after an apparently successful link. Container restarts, reconnect retries, and persistent volumes cannot recover the session because
whatsapp-web.jsdeletes the credentials after the WhatsApp-side logout.Investigation and root-cause isolation
The following possible causes were tested and did not change the outcome:
openwaOS user, and the production Chromium flags;readyreconciliation versus the original enginereadyevent;Two controls were important:
whatsapp-web.jsclient, run inside the same production container with the same Chrome binary, OS user, account, and WhatsApp Web build, survived its five-minute reload.whatsapp-web.jsclient also survived the same reload and stayed authenticated.The relevant behavioral difference was in
SessionService.handleEngineReady(). OpenWA immediately ran:That eager history fetch happens after the new companion becomes ready but before its first scheduled Web reload.
Single-variable A/B test
The production-equivalent test was repeated with only the eager Status seed changed:
readypost_logout=1, emittedLOGOUT, removed the linked device, and deleted LocalAuthCONNECTED/hasSynced; no logout occurred and credentials remained presentSuccessful run timeline:
READYCONNECTED,hasSynced=true, withWWebJSavailableREADY; nopost_logout, noLOGOUT, and the profile remained intactThis does not imply that every WhatsApp account is rejected by the history request. It establishes that, for affected accounts, the immediate
status@broadcastfetch is the causal OpenWA-side trigger. Because the backfill is optional enrichment rather than a session-readiness requirement, making it opt-in is the safer default.Changes
Session behavior
STATUS_SEED_ON_READYparsing with the accepted truthy valuestrue,1,yes, andon.seedStatuses()when the variable is absent or false.status_seed_on_ready_disabledwhen the backfill is skipped.Configuration
STATUS_SEED_ON_READY=falsein.env.example.docker-compose.yml, defaulting tofalse.Documentation
Tests
readyby default.Compatibility and tradeoffs
Validation
Automated checks on this branch
npx eslint src/modules/session/session.service.ts src/modules/session/session.service.spec.ts— passed.npm test -- --runInBand src/modules/session/session.service.spec.ts— 236/236 passed.docker compose -f docker-compose.yml config --quiet— passed.git diff --cached --check— passed (only local Windows LF/CRLF conversion notices).Production-equivalent runtime checks
v0.12.2and rebuilding, the existing linked profile restored automatically and reachedREADYin about four seconds without a new QR.status_seed_on_ready_disableddebug event.Existing upstream build issue observed locally
npm run buildcurrently stops at an unrelated TypeScript error insrc/engine/adapters/whatsapp-web-js.adapter.ts:523, wheremsg.downloadMedia()can resolveundefinedbutresolveBoundedaccepts onlyMessageMedia | null. That file is byte-for-byte unchanged fromupstream/mainin this branch and is outside this PR's diff. The completeSessionServicetest suite and lint checks for the changed TypeScript files pass.Rollout
No action is required for affected installations after updating: the safer behavior is the default. Operators who intentionally depend on pre-connection Status history should enable
STATUS_SEED_ON_READY=trueafter validating that their accounts remain linked through the first scheduled WhatsApp Web reload.